package LC12;

/**
 * 1137. 第 N 个泰波那契数
 * 泰波那契序列 Tn 定义如下：
 * T0 = 0, T1 = 1, T2 = 1, 且在 n >= 0 的条件下 Tn+3 = Tn + Tn+1 + Tn+2
 * 给你整数 n，请返回第 n 个泰波那契数 Tn 的值。
 */
public class LC1137 {

    public static void main(String[] args) {
        System.out.println(tribonacci(2));
    }

    public static int tribonacci(int n) {
        if (n == 0) {
            return 0;
        } else if (n == 1) {
            return 1;
        } else if (n == 2) {
            return 1;
        } else {
            int a = 0;
            int b = 1;
            int c = 1;
            int s = 2;
            for (int i = 3; i < n + 1; i++) {
                s = a + b + c;
                a = b;
                b = c;
                c = s;

            }
            return s;
        }
    }
}
